﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HostClientConfig.aspx.cs" Inherits="HJT212_Protocol_WebServer.HostClientConfig" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>上位机配置</title>
    <link rel="stylesheet" type="text/css" href="Content/themes/base/jquery.ui.all.css" />
    <script type="text/javascript" src="Scripts/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="Scripts/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="Scripts/jQuery.timer1.2.js"></script>
    <script type="text/javascript" src="Scripts/Common.js"></script>
    <link rel="stylesheet" type="text/css" href="Content/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="Content/icon.css" />
    <link rel="stylesheet" type="text/css" href="Content/demo.css" />
    <script src="Content/ui/jquery.ui.core.js"></script>
    <script src="Content/ui/jquery.ui.widget.js"></script>
    <script src="Content/ui/jquery.ui.button.js"></script>
    <link rel="stylesheet" type="text/css" href="Content/themes/sites.css" />
    <script>
        $(function () {
            $("input:submit, a, button", ".demo").button();
            $("a", ".demo").click(function () { return false; });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="border: solid 1px gray; width: 904px; height: 400px; margin: -200px 0 0 -150px;
        position: absolute; top: 40%; left: 30%;">
        <div class="demo">
            <div style="width: 800px; margin: 0; float: left; padding-left: 10px; font-size: 10px !important;">
                <asp:Button ID="Button2" runat="server" Text="新建类别" Height="30px" Width="80px" OnClientClick="appendClas();return false;" />
                &nbsp;&nbsp;
                <asp:Button ID="Button3" runat="server" Text="新建站点" Height="30px" Width="80px" OnClientClick="appendNode();return false;" />
                &nbsp;&nbsp;
                <asp:Button Height="30px" ID="Button1" OnClientClick="editNode();return false;" runat="server"
                    Text="编 辑" Width="80px" />
                &nbsp;&nbsp;
                <asp:Button ID="Button4" runat="server" Text="确 认" Height="30px" Width="80px" OnClientClick="saveNode();return false;" />
                &nbsp;&nbsp;
                <asp:Button ID="Button5" runat="server" Text="取 消" Height="30px" Width="80px" OnClientClick="cancelNode();return false;" />
                &nbsp;&nbsp;
                <asp:Button ID="Button6" runat="server" Text="删 除" Height="30px" Width="80px" OnClientClick="remove();return false;" />
                &nbsp;&nbsp;
                <asp:Button ID="Button7" runat="server" Text="刷  新" Height="30px" Width="80px" OnClientClick="reload();return false;" />
            </div>
        </div>
        <div style="border: solid 1px gray; width: 904px; height: 345px; margin-top: 30px;">
            <table id="test">
            </table>
        </div>
    </div>
    </form>
    <script type="text/javascript">

        var Opt = "insert";

        function GetData() {
            $('#test').treegrid({
                title: '数采仪配置',
                iconCls: 'icon-save',
                width: 904,
                height: 345,
                nowrap: false,
                rownumbers: true,
                animate: true,
                collapsible: true,
                url: 'HostClientOpt.ashx?Type=ClientTreeList',
                idField: 'ID',
                treeField: 'MN',
                frozenColumns: [[
                    {
                        title: 'MN', field: 'MN', width: 500, editor: 'text',align:'left'
                    }
                ]],
                columns: [[
                    //{ field: 'MN', title: 'MN号', width: 150 },
                    { field: 'MCNName', title: '站点名称', width: 160, editor: 'text' },
                    { field: 'PW', title: '密码', width: 120, editor: 'text' },
                    {
                        field: 'OnLineState', title: '在线状态', width: 90, editor: 'text',
                        formatter: function (value, rec) {
                            if (value == 2) {
                                return '在线';
                            }
                            else if (value == 0) {
                                return '离线';
                            }
                            else {
                                return '';
                            }
                        },
                        styler: function (value, row, index) {
                            if (value == 1) {
                                return 'color:red;';
                            }
                        }
                    },
                    { field: 'IsLeaf', title: '是否站点', width: 120, editor: 'text', hidden: true}
                ]],
                onBeforeLoad: function (row, param) {
                    if (row) {
                        $(this).treegrid('options').url = 'HostClientOpt.ashx?Type=SubClientTreeList&ID=' + row.ID;
                    } else {
                        $(this).treegrid('options').url = 'HostClientOpt.ashx?Type=ClientTreeList';
                    }
                },
                onLoadSuccess: function (row, data) {
                    var node = $('#test').treegrid('getRoot');
                    if (node) {
                        $('#test').treegrid('expand', node.ID);
                    }
                },
                onContextMenu: function (e, row) {
                    e.preventDefault();
                    $(this).treegrid('unselectAll');
                    $(this).treegrid('select', row.ID);
                    $('#mm').menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                },
                onDblClickRow: function (row) {
                    if(row) {
                        editNode();
                    }
                }

            });
        };
        
        function editNode() {
            var node = $('#test').treegrid('getSelected');
            if (node) {
                Opt = "update";
                $('#test').treegrid('beginEdit', node.ID);
            }
        }
        function saveNode() {
            var node = $('#test').treegrid('getSelected');
            if (node) {
                
                $('#test').treegrid('endEdit', node.ID);
                
                showProcess(true, '温馨提示', '正在提交数据...');
                $.ajax({
                    type: "post",
                    url: "HostClientOpt.ashx?Type=Edit&Opt=" + Opt,
                    data: {
                        ID: node.ID,
                        MN: node.MN,
                        MCNName: node.MCNName,
                        PW: node.PW,
                        OnLineState: node.OnLineState,
                        ParentID: node.ParentID,
                        IsLeaf: node.IsLeaf
                    }, //数据
                    timeout: 5000,//超时时间设定
                    error: function () {
                        showProcess(false);
                        $.messager.alert('提示', '操作失败！', 'error');
                    },//错误处理
                    global: false,
                    success: function (result) {
                        showProcess(false);
                        if (result == "ok") {
                            $.messager.alert('提示', "操作成功", 'info');
                        }
                        else if (result == "Exist")
                        {
                            $.messager.alert('提示', "存在相应的MN号的站点,请重新填写MN", 'warning');
                        }
                    }
                }); //成功的回调函数

            }
        }
        function cancelNode() {
            var node = $('#test').treegrid('getSelected');
            if (node) {
                $('#test').treegrid('cancelEdit', node.ID);
            }
        }
        function appendNode() {
            var node = $('#test').treegrid('getSelected');
            if (!node) return false;
            var id = NewId();
            var data = [{
                ID: id,
                MN: 'MN号',
                MCNName: '名称',
                OnLineState: 0,
                state: 'open',
                ParentID: node.ID,
                IsLeaf: 1
            }];
            $('#test').treegrid('append', {
                parent: (node ? node.ID : null),
                data: data
            });
            $('#test').treegrid('unselect', node.ID);
            $('#test').treegrid('select', id);
            $('#test').treegrid('beginEdit', id);
            Opt = "insert";
        }
        function appendClas() {
            var node = $('#test').treegrid('getSelected');
            if (!node) return false;
            var id = NewId();
            var data = [{
                ID: id,
                MN: '',
                MCNName: '类别名称',
                OnLineState: 0,
                state: 'closed',
                ParentID: node.ID,
                IsLeaf: 0
            }];
            $('#test').treegrid('append', {
                parent: (node ? node.ID : null),
                data: data
            });
            $('#test').treegrid('unselect', node.ID);
            $('#test').treegrid('select', id);
            $('#test').treegrid('beginEdit', id);
            Opt = "insert";
        }
        function remove() {
            var node = $('#test').treegrid('getSelected');
            if (node) {
                Opt = "del";
                showProcess(true, '温馨提示', '正在提交数据...');
                $.ajax({
                    type: "post",
                    url: "HostClientOpt.ashx?Type=Edit&Opt=" + Opt,
                    data: {
                        ID: node.ID,
                        MN: node.MN,
                        MCNName: node.MCNName,
                        PW: node.PW,
                        OnLineState: 0,
                        ParentID: node.ParentID,
                        IsLeaf: 1
                    }, //数据
                    timeout: 5000,//超时时间设定
                    error: function (result) {
                        showProcess(false);
                        $.messager.alert('提示', '操作失败！', 'error');
                    },//错误处理
                    global: false,
                    success: function (result) {
                        showProcess(false);
                        if (result == "ok") {
                            $.messager.alert('提示', "操作成功", 'info');
                            $('#test').treegrid('remove', node.ID);
                        }
                        else {
                            $.messager.alert('提示', '操作失败！', 'error');
                        }
                    }
                }); //成功的回调函数
            }
        }

        function reload() {
            var node = $('#test').treegrid('getSelected');
            if (node) {
                $('#test').treegrid('reload', node.ID);
            } else {
                $('#test').treegrid('reload');
            }
        }
        $(document).ready(function () {
            GetData();
        });
        $('body').everyTime('30s', function () {
        });
    </script>
</body>
</html>
